package com.zyx.maildemo.service;

import com.zyx.maildemo.entity.Roles;
import com.zyx.maildemo.entity.example.RolesExample;
import com.zyx.maildemo.mapper.RolesMapper;
import com.zyx.maildemo.mapper.UserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @ClassName: RolesServiceImpl
 * @author: zyx
 * @E-mail: 1377631190@qq.com
 * @DATE: 2019/7/27 13:15
 */
@Service
public class RolesService {

    @Autowired
    private RolesMapper rolesMapper;

    @Autowired
    private UserRoleMapper userRoleMapper;

    /**
     * 根据角色标志获取一个角色
     */
    public Roles findOne(String sign) {
        RolesExample rolesExample = new RolesExample();
        rolesExample.createCriteria().andSignEqualTo(sign);
        List<Roles> roles = rolesMapper.selectByExample(rolesExample);
        if (CollectionUtils.isEmpty(roles))
            return null;
        return roles.get(0);
    }

}
